package com.lbc.service.impl;

import com.lbc.bean.dto.PictureDTO;
import com.lbc.bean.entity.Picture;
import com.lbc.bean.vo.PictureVO;
import com.lbc.common.utils.JwtUtils;
import com.lbc.dao.custom.CtPictureMapper;
import com.lbc.service.PictureService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author xyl
 * @date 2021-03-17 19:52
 */
@Service
public class PictureServiceImpl implements PictureService {
    @Autowired
    private CtPictureMapper pictureMapper;

    @Override
    public int add(PictureDTO pictureDTO) {
        pictureDTO.setPictureId(null);
        Date date = new Date();
        Picture picture = new Picture();
        BeanUtils.copyProperties(pictureDTO,picture);
        picture.setCreateBy(JwtUtils.getUserId());
        picture.setCreateTime(date);
        picture.setUpdateTime(date);
        return pictureMapper.insertSelective(picture);
    }

    @Override
    public int modify(PictureDTO pictureDTO) {
        Picture picture = new Picture();
        BeanUtils.copyProperties(pictureDTO,picture);
        picture.setUpdateBy(JwtUtils.getUserId());
        picture.setUpdateTime(new Date());
        return pictureMapper.updateByPrimaryKeySelective(picture);
    }

    @Override
    public int remove(Integer pictureId) {
        return pictureMapper.deleteByPrimaryKey(pictureId);
    }

    @Override
    public List<PictureVO> list() {
        return pictureMapper.selectAll();
    }
}
